package work.zhengyun.demo.controller;

import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import work.zhengyun.demo.entity.User;

/**
 * @author zhengyun
 * @date 2019/11/26 15:38
 */

@Api(value = "测试各种方法", tags = {"测试使用Controller"})
@RestController
public class Swagger2TestController {
    @ApiOperation(value = "测试Swagger2接口", notes = "传入编号！")
    @ApiImplicitParam(name = "id", value = "id", required = true)
    @RequestMapping(value = "/swaTest2/{id}", method = RequestMethod.GET)
    public String TestSwa2(@PathVariable("id") Integer id) {
        System.out.println("swaTest！");
        System.out.println("id:"+id);
        //  Optional<UserInfo> user = userRepository.findById(id);
        User user = new User();
        user.setName("tester");
        user.setAge(12);
        return user.toString();
    }

    @ApiOperation(value = "swaTest3", notes = "测试GET！")
    @ApiImplicitParam(name = "name", value = "用户name")
    @RequestMapping(value = "/swaTest3", method = RequestMethod.GET)
    public String TestSwa3(@RequestParam("name") String name) {
        System.out.println("swaTest！");
        return name;
    }

    @ApiOperation(value = "swaTest4", notes = "测试POST！")
    @RequestMapping(value = "/swaTest4", method = RequestMethod.POST)
    public String TestSwa4(@RequestBody JSONObject jsonObject) {
        System.out.println("swaTest4！" + jsonObject.toString());
        String str = jsonObject.toString();
        return str;
    }

    @ApiOperation(value = "swaTest5", notes = "测试对象传值！")
    @RequestMapping(value = "/swaTest5", method = RequestMethod.POST)
    public String TestSwa5(User user) {
        return user.toString();
    }
}
